package com.miao.hong.fang.course;

import java.io.Serializable;
import java.sql.Timestamp;

import com.miao.hong.fang.IConstants;
import com.miao.hong.fang.util.Utils;

public class CourseTO implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 6860832875325792853L;
	private String courseId;
	private String courseTitle;
	private Integer coursePeriod;
	private Timestamp courseStartTime;
	private Timestamp courseEndTime;
	private Integer coursePrice;
	private String courseCity;
	private String courseCategory;
	private String courseTarget;
	private String courseSponsor;
	private String courseTelphone;
	private String courseContact;
	private String courseBackground;
	private String courseMainPoint;
	private String isHotCourse;
	private String isRecommendCourse;
	private String isPublicCourse;
	private String courseTeacher;
	private int version;
	
	public String getCourseId() {
		return courseId;
	}
	public void setCourseId(String courseId) {
		this.courseId = courseId;
	}
	public String getCourseTitle() {
		return courseTitle;
	}
	public void setCourseTitle(String courseTitle) {
		this.courseTitle = courseTitle;
	}
	public Integer getCoursePeriod() {
		return coursePeriod;
	}
	public void setCoursePeriod(Integer coursePeriod) {
		this.coursePeriod = coursePeriod;
	}
	public Timestamp getCourseStartTime() {
		return courseStartTime;
	}
	public void setCourseStartTime(Timestamp courseStartTime) {
		this.courseStartTime = courseStartTime;
	}
	public Timestamp getCourseEndTime() {
		
		if(courseEndTime != null) {
			return courseEndTime;
		}else {
			if(courseStartTime != null && coursePeriod != null) {
				return Utils.addDays(courseStartTime, coursePeriod);
			}
		}
		return courseEndTime;
	}
	public void setCourseEndTime(Timestamp courseEndTime) {		
			this.courseEndTime = courseEndTime;	
	}
	
	public String getCourseEndTimeAsStr() {
		return Utils.timestampToString(courseEndTime, IConstants.COURSE_START_TIME_FORMAT);
	}
	
	public Integer getCoursePrice() {
		return coursePrice;
	}
	public void setCoursePrice(Integer coursePrice) {
		this.coursePrice = coursePrice;
	}
	public String getCourseCity() {
		return courseCity;
	}
	public void setCourseCity(String courseCity) {
		this.courseCity = courseCity;
	}
	public String getCourseCategory() {
		return courseCategory;
	}
	public void setCourseCategory(String courseCategory) {
		this.courseCategory = courseCategory;
	}
	public String getCourseTarget() {
		return courseTarget;
	}
	public void setCourseTarget(String courseTarget) {
		this.courseTarget = courseTarget;
	}
	public String getCourseSponsor() {
		return courseSponsor;
	}
	public void setCourseSponsor(String courseSponsor) {
		this.courseSponsor = courseSponsor;
	}
	public String getCourseTelphone() {
		return courseTelphone;
	}
	public void setCourseTelphone(String courseTelphone) {
		this.courseTelphone = courseTelphone;
	}
	public String getCourseContact() {
		return courseContact;
	}
	public void setCourseContact(String courseContact) {
		this.courseContact = courseContact;
	}
	public String getCourseBackground() {
		return courseBackground;
	}
	public void setCourseBackground(String courseBackground) {
		this.courseBackground = courseBackground;
	}
	public String getCourseMainPoint() {
		return courseMainPoint;
	}
	public void setCourseMainPoint(String courseMainPoint) {
		this.courseMainPoint = courseMainPoint;
	}
	public String getIsHotCourse() {
		return isHotCourse;
	}
	public void setIsHotCourse(String isHotCourse) {
			this.isHotCourse = isHotCourse;	
	}
	public String getIsRecommendCourse() {
		return isRecommendCourse;
	}
	public void setIsRecommendCourse(String isRecommendCourse) {
			this.isRecommendCourse = isRecommendCourse;	
	}
	public String getIsPublicCourse() {
		return isPublicCourse;
	}
	public void setIsPublicCourse(String isPublicCourse) {
			this.isPublicCourse = isPublicCourse;	
	}
	public String getCourseTeacher() {
		return courseTeacher;
	}
	public void setCourseTeacher(String courseTeacher) {
		this.courseTeacher = courseTeacher;
	}
	public int getVersion() {
		return version;
	}
	public void setVersion(int version) {
		this.version = version;
	}
	
	public void setCourseStartTimeAsStr(String courseStartTimeAsStr) {
		//  2010-09-05
		this.courseStartTime = Utils.stringToTimestamp(courseStartTimeAsStr, IConstants.COURSE_START_TIME_FORMAT);		
	}
	public String getCourseStartTimeAsStr() {

		return Utils.timestampToString(courseStartTime, IConstants.COURSE_START_TIME_FORMAT);
	}
	
	public String getCourseStartDtAsStr() {
		
		return courseStartDtAsStr();
	}
	private String courseStartDtAsStr() {
		int month = courseStartTime.getMonth() + 1;
		if(month < 10) {
			return "0" + month + "-" + courseStartTime.getDate();
		} else {
			return month + "-" + courseStartTime.getDate();
		}
	}
	
	public String getStatus() {

		if(this.getCourseEndTime().before(new Timestamp(System.currentTimeMillis()))) {
			return "已结束";
		}
		return "有效";
	}
}
